package vistas;

import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JInternalFrame;
import javax.swing.JTextField;
import java.awt.Rectangle;
import java.rmi.RemoteException;

import javax.swing.JLabel;
import javax.swing.JButton;

import controlador.Controlador;

public class AgregarUnaMesa extends JInternalFrame {

	private Controlador controlador;
	private JPanel jContentPane = null;
	private JTextField nroMesa = null;
	private JLabel nroDeMesa = null;
	private JButton agregar = null;
	private JButton salir = null;

	/**
	 * This is the xxx default constructor
	 */
	public AgregarUnaMesa() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(300, 200);
		this.setTitle("Agregar una Mesa");
		this.setContentPane(getJContentPane());
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			nroDeMesa = new JLabel();
			nroDeMesa.setBounds(new Rectangle(40, 35, 110, 30));
			nroDeMesa.setText("Numero de mesa:");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getNroMesa(), null);
			jContentPane.add(nroDeMesa, null);
			jContentPane.add(getAgregar(), null);
			jContentPane.add(getSalir(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes nroMesa	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getNroMesa() {
		if (nroMesa == null) {
			nroMesa = new JTextField();
			nroMesa.setBounds(new Rectangle(180, 35, 50, 30));
		}
		return nroMesa;
	}

	/**
	 * This method initializes agregarYabrir	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getAgregar() {
		if (agregar == null) {
			agregar = new JButton();
			agregar.setBounds(new Rectangle(30, 95, 100, 40));
			agregar.setText("Agregar");
			agregar.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					String numero =  getNroMesa().toString();
					int n= Integer.parseInt(numero);
					try {
						controlador.agregarMesa(n);
					} catch (RemoteException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}}});
		}
		return agregar;
	}

	/**
	 * This method initializes salir	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getSalir() {
		if (salir == null) {
			salir = new JButton();
			salir.setBounds(new Rectangle(160, 95, 100, 40));
			salir.setText("Cancelar");
			salir.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					dispose();
				}
			});
		}
		return salir;
	}

	public void setControlador(Controlador controlador) {
		this.controlador = controlador;
	}
	
}

